package in.smartbillpay.web.models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Min;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Entity
@Table(name="SBPUser")
public class SBPUser implements Serializable, UserDetails {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		
	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="Id") 
	private int id;
	
	@NotEmpty(message="UserName field is mandatory.")
	@Column(name="UserName",length=35,unique=true)
	private String username;
	
	@NotEmpty(message="Password field is mandatory.")
	@Column(name="Password",length=50)
	private String password;
	
	@Column(name="Enabled")
	private boolean enabled;

	@NotEmpty(message="FirstName field is mandatory.")
	@Column(name="FirstName",length=25)
	private String firstName;
	
	@Column(name="MiddleName",length=25)
	private String middleName;
	
	@NotEmpty(message="LastName field is mandatory.")
	@Column(name="LastName",length=25)
	private String lastName;
	
	@Column(name="BirthDate")
	@Temporal(value = TemporalType.DATE)
	private Date birthDate;
	
	@Column(name="Email", length=50)
	private String email;
	
	@Min(value = 1000000000)
	@Column(name="MobileNumber")
	private long mobileNumber;
	
	@NotEmpty(message="Street field is mandatory.")
	@Column(name="Street")
	private String street;
	
	@NotEmpty(message="Area field is mandatory.")
	@Column(name="Area",length=50)
	private String area;
	
	@Min(value = 100000)
	@Column(name="PinCode")
	private int pinCode;
	
	@NotEmpty(message="SecurityQuestion field is mandatory.")
	@Column(name="SecurityQuestion")
	private String securityQuestion;
	
	@NotEmpty(message="SecurityAnswer field is mandatory.")
	@Column(name="SecurityAnswer", length=50)
	private String securityAnswer;
	
	//@NotEmpty(message="Status field is mandatory.")
	@Column(name="Status", length=15)
	private String status;
	
	@Column(name="StatusRemark")
	private String statusRemark;
	
	@Column(name="RegisterDate")
	@Temporal(value = TemporalType.DATE)
	private Date registerDate;
	
	@Column(name="TerminationDate")
	@Temporal(value = TemporalType.DATE)
	private Date terminationDate;
	
	@Column(name="LastUpdateDate")
	@Temporal(value = TemporalType.TIMESTAMP)
	private Date lastUpdateDate;
	
	@ManyToOne
	@JoinColumn(name="CityId")
	private City city;
	
	@ManyToMany(fetch=FetchType.EAGER)
	private Collection<Authority> authorityList = new ArrayList<Authority>();
	
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the enabled
	 */
	public boolean isEnabled() {
		return enabled;
	}

	/**
	 * @param enabled the enabled to set
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the birthDate
	 */
	public Date getBirthDate() {
		return birthDate;
	}

	/**
	 * @param birthDate the birthDate to set
	 */
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the mobileNumber
	 */
	public long getMobileNumber() {
		return mobileNumber;
	}

	/**
	 * @param mobileNumber the mobileNumber to set
	 */
	public void setMobileNumber(long mobileNumber) {
		this.mobileNumber = mobileNumber;
	}

	/**
	 * @return the street
	 */
	public String getStreet() {
		return street;
	}

	/**
	 * @param street the street to set
	 */
	public void setStreet(String street) {
		this.street = street;
	}

	/**
	 * @return the area
	 */
	public String getArea() {
		return area;
	}

	/**
	 * @param area the area to set
	 */
	public void setArea(String area) {
		this.area = area;
	}

	/**
	 * @return the city
	 */
	public City getCity() {
		return city;
	}

	/**
	 * @param city the city to set
	 */
	public void setCity(City city) {
		this.city = city;
	}

	/**
	 * @return the pinCode
	 */
	public int getPinCode() {
		return pinCode;
	}

	/**
	 * @param pinCode the pinCode to set
	 */
	public void setPinCode(int pinCode) {
		this.pinCode = pinCode;
	}

	/**
	 * @return the registerDate
	 */
	public Date getRegisterDate() {
		return registerDate;
	}

	/**
	 * @param registerDate the registerDate to set
	 */
	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	/**
	 * @return the lastUpdateDate
	 */
	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}

	/**
	 * @param lastUpdateDate the lastUpdateDate to set
	 */
	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}

	/**
	 * @return the authorityList
	 */
	public Collection<Authority> getAuthorityList() {
		return authorityList;
	}

	/**
	 * @param authorityList the authorityList to set
	 */
	public void setAuthorityList(Collection<Authority> authorityList) {
		this.authorityList = authorityList;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String userName) {
		this.username = userName;
	}

	/**
	 * @return the securityQuestion
	 */
	public String getSecurityQuestion() {
		return securityQuestion;
	}

	/**
	 * @param securityQuestion the securityQuestion to set
	 */
	public void setSecurityQuestion(String securityQuestion) {
		this.securityQuestion = securityQuestion;
	}

	/**
	 * @return the securityAnswer
	 */
	public String getSecurityAnswer() {
		return securityAnswer;
	}

	/**
	 * @param securityAnswer the securityAnswer to set
	 */
	public void setSecurityAnswer(String securityAnswer) {
		this.securityAnswer = securityAnswer;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * @return the statusRemark
	 */
	public String getStatusRemark() {
		return statusRemark;
	}

	/**
	 * @param statusRemark the statusRemark to set
	 */
	public void setStatusRemark(String statusRemark) {
		this.statusRemark = statusRemark;
	}

	/**
	 * @return the middleName
	 */
	public String getMiddleName() {
		return middleName;
	}

	/**
	 * @param middleName the middleName to set
	 */
	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public Collection<? extends GrantedAuthority> getAuthorities() {
		return getAuthorityList();
	}

	
	public boolean isAccountNonExpired() {
		return true;
	}

	public boolean isAccountNonLocked() {
		return true;
	}

	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	/**
	 * @return the terminationDate
	 */
	public Date getTerminationDate() {
		return terminationDate;
	}

	/**
	 * @param terminationDate the terminationDate to set
	 */
	public void setTerminationDate(Date terminationDate) {
		this.terminationDate = terminationDate;
	}


}
